package com.jch.dm.chapter_17_observer;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author: Administrator
 * @create: 2020/04/08 11:37
 **/
public abstract class NumberGenerator {
    /**
     * 保存Observers
     */
    private ArrayList observers = new ArrayList();

    /**
     * 注册Observer
     */
    public void addObserver(Observer observer){
        observers.add(observer);
    }
    /**
     * 删除Observer
     */
    public void deleteObserver(Observer observer){
        observers.remove(observer);
    }
    /**
     * 向Observer发送通知
     */
    public void notifyObservers(){
        Iterator it = observers.iterator();
        while(it.hasNext()){
            Observer o = (Observer) it.next();
            o.update(this);
        }
    }
    /**
     * 获取数值
     * @return 数值
     */
    public abstract int getNumber();
    /**
     * 生成数值
     */
    public abstract void execute();
}
